package com.ling.module1sbbyyds.controller.usercenter;

import com.ling.sbbyyds.interaction.param.LoginUser;
import com.ling.module1sbbyyds.service.user.LoginService;
import com.ling.sbbyyds.interaction.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 天道酬勤、学无止境
 *
 * @Description: 登录控制类
 * @author: ling
 * @date: 2022年03月08日
 */
@RestController
@RequestMapping("api/login/")
public class LoginController {

    @Autowired(required = false)
    private LoginService loginService;

    /**
    * @Description: 密码登录
    * @author: ling
    * @date: 2022/3/15
    * @param loginUser: 手机号+密码
    * @Return: com.ling.module1sbbyyds.interaction.Return.Result
    */
    @PostMapping("passwordlogin")
    public ResultVo passwordLogin(@RequestBody LoginUser loginUser){

        return loginService.passwordLogin(loginUser);
    }

    /**
    * @Description: 验证码登录
    * @author: ling
    * @date: 2022/3/27
    * @param loginUser: 手机号 +验证码
    * @Return: com.ling.module1sbbyyds.interaction.Return.Result
    */
    @PostMapping("codelogin")
    public ResultVo codeLogin(@RequestBody LoginUser loginUser){

        return loginService.codeLogin(loginUser);
    }



    /**
    * @Description: 手机号请求验证码
    * @author: ling 
    * @date: 2022/3/20 
    * @param phone: 手机号
    * @Return: com.ling.module1sbbyyds.interaction.Return.Result
    */
    @GetMapping("code")
    public ResultVo validateCode(@RequestParam("phone") String phone) throws IOException {

        return loginService.returnCode(phone);
    }

    @GetMapping("isLogin/loginOut")
    public ResultVo loginOut() {

        return loginService.loginOut();

    }


}
